package com.cskaoyan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

    @RequestMapping("hello")
    public ModelAndView hello1() {
        ModelAndView modelAndView = new ModelAndView();
        //相对于web资源根路径(webapp)的视图名 → 最左边/
        modelAndView.setViewName("/hello.jsp");
        //设置Model key=value的形式
        modelAndView.addObject("content", "world");
        return modelAndView;
    }

    //如果响应字符串作为视图名，不要增加@ResponseBody
    @RequestMapping("hello2")
    public String hello2(Model model) {
        model.addAttribute("content", "world2");
        return "/hello.jsp";
    }
}
